g=int(input())
count=0
maxi=0
kom=[]
komm=[0]
if 999<g<10000:
     s = str(g)
     g1=int(s[0])
     g2=int(s[0]+s[1])
     g3=int(s[0]+s[1]+s[2])
     g4=int(s[0]+s[1]+s[2]+s[3])
     g5=int(s[1])
     g6=int(s[1]+s[2])
     g7=int(s[1]+s[2]+s[3])
     g8=int(s[1])
     g9=int(s[2]+s[3])
     g10=int(s[3])
     kom=[g1,g2,g3,g4,g5,g6,g7,g8,g9,g10]
     for i in kom:
           for d in range (1,50001):
                  if i%d==0:
                        count+=1
           if count==2:
                  komm.append(i)
           count=0
     print(max(komm))
else:
    print(0)
